package br.com.rodrigomarangon.rmcalculos;

import java.text.DecimalFormat;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Fgts extends Activity {

	EditText edsalariofgts, edmesesfgts;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_fgts);
		edsalariofgts = (EditText) findViewById(R.id.edsalariofgts);
		edmesesfgts = (EditText) findViewById(R.id.edmesesfgts);
		Button botaovoltamenu = (Button) findViewById(R.id.btvoltafgts);
		Button botaolimpafgts = (Button) findViewById(R.id.btlimpafgts);
		Button botaosomafgts = (Button) findViewById(R.id.btcalculafgts);
		botaosomafgts.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if

                (edsalariofgts.getText().toString().equals("")||

                             edmesesfgts.getText().toString().equals("")){

					AlertDialog.Builder dialogo =

					new

               AlertDialog.Builder(Fgts.

               this

               );dialogo.setTitle("Aviso");dialogo.setMessage("Preencha todos os Campos");dialogo.setNeutralButton("Ok",

               null

               );dialogo.show();}

               else

               {
				double salariofgts = Double.parseDouble(edsalariofgts.getText()
						.toString());

				double mesesfgts = Double.parseDouble(edmesesfgts.getText()
						.toString());
				double valorfgts = salariofgts * 0.08;
				DecimalFormat df = new DecimalFormat("0.00");
				String saidavalor = df.format(valorfgts);
				double resultadofgts = valorfgts * mesesfgts;
				DecimalFormat dv = new DecimalFormat("0.00");
				String saidaresultado = dv.format(resultadofgts);

				Intent intent = new Intent();
				intent.setClass(Fgts.this, Resultado_FGTS.class);
				intent.putExtra("saidaresultado", saidaresultado);
				intent.putExtra("saidaresultadofgtsmes", saidavalor);
				intent.putExtra("saidaresultadomes", edmesesfgts.getText().toString());
				startActivity(intent);

				finish();

			}

		}
		}
		);
		botaovoltamenu.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				Intent intent = new Intent();
				intent.setClass(Fgts.this, Inicio.class);

				startActivity(intent);

				finish();
			}

		});
		botaolimpafgts.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				edsalariofgts.setText("");
				edmesesfgts.setText("");
				edsalariofgts.requestFocus();
				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.fgts, menu);
		return true;
	}

}
